package com.sdp.irrigation.utils;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.serializer.SerializerFeature;

public class JsonUtils {

//	private static final PropertyFilter filter = new PropertyFilter() {
//
//		@Override
//		public boolean apply(Object object, String name, Object value) {
//			if ("protocolInstance".equals(name)) {
//				return false;
//			}
//			return true;
//		}
//	};
	
	public static String toJSONString(Object obj) {
		if (obj != null) {
			return JSON.toJSONString(obj, SerializerFeature.SortField);
		}
		return null;
		//return JSON.toJSONString(obj, filter);
	}
	
	public static <T> T parseBean(String text , Class<T> clazz)
	{
		return JSON.parseObject(text, clazz, Feature.OrderedField);
	}
	
	public static <T> List<T> parseList(String text , Class<T> clazz)
	{
		return JSON.parseArray(text, clazz);
	}
	
}
